package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.Cpu;
import com.accelstack.cmp.repository.CpuRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * CPU Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CpuService {
    
    private final CpuRepository cpuRepository;
    
    @Transactional
    public Cpu create(Cpu cpu) {
        return cpuRepository.save(cpu);
    }
    
    @Transactional
    public Cpu update(Cpu cpu) {
        return cpuRepository.save(cpu);
    }
    
    @Transactional
    public void deleteById(Long id) {
        cpuRepository.deleteById(id);
    }
    
    public Optional<Cpu> findById(Long id) {
        return cpuRepository.findById(id);
    }
    
    public List<Cpu> findAll() {
        return cpuRepository.findAll();
    }
    
    public Page<Cpu> findAll(Pageable pageable) {
        return cpuRepository.findAll(pageable);
    }
    
    public List<Cpu> findByServerId(Long serverId) {
        return cpuRepository.findByServerId(serverId);
    }
}

